class MyBolockingQueue{
    private String[] elems;

    public MyBolockingQueue(int capcity){
        this.elems=new String[capcity];
    }
    private Object locker=new Object();
    private int head=0;
    private int tail=0;
    private int size=0;

    public void put(String s) throws InterruptedException {
        synchronized (locker){
            while (size==elems.length){
                //等待
                locker.wait();
            }
            elems[tail]=s;
            tail++;
            if (tail==elems.length){
                tail=0;
            }

            size++;

            locker.notify();
        }
    }


    public String take(){
        String elem=null;
        while (size==0){
            //等待
        }
        elem=elems[head];
        head++;
        if (head==elems.length){
            head=0;
        }
        size--;
        locker.notify();
        return elem;

    }

}





public class Test {
    public static void main(String[] args) {
        MyBolockingQueue queue=new MyBolockingQueue(100);
        Thread t1=new Thread(()->{
           while (true){
               try {
                   queue.put("dsa");
               } catch (InterruptedException e) {
                   throw new RuntimeException(e);
               }
           }
        });
    }
}
